#ifndef SOCKETSERVER_H
#define SOCKETSERVER_H

#include "unp.h"
#include "SocketWrapper.h"

class SocketServer
{
public:
	SocketServer(in_port_t port);
	SocketServer(in_port_t port, sa_family_t family);
	SocketServer(in_addr_t address, in_port_t port, sa_family_t family);
	virtual ~SocketServer();
	
	void start();

	in_port_t getPort() { return ntohs(_servaddr.sin_port); }

protected:
	virtual void setup() {}
	virtual void teardown() {}
	virtual void handleAccept(int connfd, struct sockaddr_in* clientaddress) = 0;

	int _listenfd;
	struct sockaddr_in _servaddr;

private:
	void initialize(in_addr_t address, in_port_t port, sa_family_t family);
};

#endif /* SOCKETSERVER_H */

